var rooturl = "http://localhost:8088";
var $ = layui.$;
var layer = layui.layer //弹层
    , laypage = layui.laypage //分页
    , laydate = layui.laydate //日期
    , table = layui.table //表格
    , carousel = layui.carousel //轮播
    , upload = layui.upload //上传
    , element = layui.element //元素操作
    , slider = layui.slider //滑块
    , dropdown = layui.dropdown //下拉菜单
    , form = layui.form
    , util = layui.util
    ,dropdown = layui.dropdown

//form模拟下载
$.download = function (url, data) {
    if (url && data) {
        var form = $('<form></form>');
        form.attr('action', url + "?rand=" + Math.random());
        form.attr('method', 'post');
        for (var item in data) {
            var input = $('<input type="text" />');
            input.attr('name', item);
            input.attr('value', data[item]);
            form.append(input);
        }
        form.appendTo('body').submit().remove();
    }
}

var commonUtil = {
    //发送ajax请求
    sendRequest: function (typex, datax, urlx, func) {
        if (func == undefined) {
            func = function (data) {
                if (data.code != "0") {
                    console.log("data: " + JSON.stringify(data));
                    layer.msg("操作失败" + JSON.stringify(data));
                    return;
                } else if (data.code == "0") {
                    console.log("data: " + JSON.stringify(data));
                    layer.msg("操作成功");
                }
            }
        }
        $.ajax({
            url: rooturl + urlx,//rooturl+""
            type: typex,//post
            data: JSON.stringify(datax),//json
            contentType: "application/json;charset=utf-8",
            success: func
        });
    },
    //打开窗口
    openNewWindow: function openNewWindow(url) {
        layer.open({
            type: 2
            , content: url//页面路径
            , maxmin: true
            , area: [(document.body.clientWidth - 10) + "px", (document.body.clientHeight - 10) + "px"]
        });
    },
    //文件下载
    downloadFile: function (url,name){
            var xhr = new XMLHttpRequest();
            xhr.open('GET', url, true);//get请求，请求地址，是否异步
            xhr.responseType = "blob";    // 返回类型blob
            xhr.onload = function () {// 请求完成处理函数
                if (this.status === 200) {
                    var blob = this.response;// 获取返回值
                    var a = document.createElement('a');
                    a.download = name;
                    a.href=window.URL.createObjectURL(blob);
                    a.click();
                }
            };
            // 发送ajax请求
            xhr.send();
    }
}

var StringUtil={
    isEmpty:function (str){
        var re=false;
        if(str==undefined||str=="undefined"||str=="null"||str==null||str==""){re=true;}
        return re;
    }
}

